// let allList: any[] = [];
export default (dynamicRouterList: any[], localRouterList: any[]) => {
    let allList: any[] = [];
    if (allList.length > 0) return allList;
    const routersMap: Array<any> = localRouterList || [];
    let _index = 0;
    const getRouters = (list: any[], parent: any) => {
        const _list: any[] = [];
        list.forEach((cur: any) => {
            if (!cur.meta || !cur.meta.filter) {
                let _cur = { ...cur };
                if (cur.path || cur.name === "home") {
                    _cur._path =
                        ((parent && parent._path) || "") + "/" + cur.path;
                    _cur._key =
                        ((parent && parent._path) || "") + "/" + cur.path;
                } else {
                    _cur._path = "";
                    _cur._key = _index + "";
                    _index += 1;
                }
                if (cur.children && cur.children.length > 0) {
                    const _sub: any = getRouters(cur.children, _cur);
                    if (_sub.length > 0) {
                        if (cur.meta && cur.meta.onlyOne && _sub.length === 1) {
                            _cur = _sub[0];
                        } else {
                            _cur.children = _sub;
                        }
                        _list.push(_cur);
                    }
                } else {
                    if (cur.meta && cur.meta.isMenu) {
                        _list.push(_cur);
                    }
                }
            }
        });
        return _list;
    };
    routersMap.forEach((cur: any) => {
        allList = allList.concat(getRouters(cur.children || [], {}));
    });
    // menuList.forEach((cur: any) => {
    //     list = list.concat(getRouters(menuList || [], {}));
    // });
    allList = allList.concat(getRouters(dynamicRouterList || [], {}));
    return allList;
};
